package br.cns.models;

import br.cns.transformations.DegreeMatrix;

public class Barabasi extends GenerativeProcedure {

	@Override
	public int[][] transform(int[][] matrix) {
		int n = matrix.length;
		int[][] nMatrix = new int[n + 1][n + 1];
		int[][] degree = DegreeMatrix.getInstance().transform(matrix);

		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				nMatrix[i][j] = matrix[i][j];
				nMatrix[j][i] = matrix[j][i];
			}
		}
		
		for (int i = 0; i < n; i++) {
			if (Math.random() < degree[i][i]/(2.0 * n)){
				nMatrix[n][i] = 1;
				nMatrix[i][n] = 1;
			}
		}

		return nMatrix;
	}

	@Override
	public int[][] grow(int[][] matrix, int time) {
		int[][] nMatrix = new int[][]{
				{0, 1, 1}, 
				{1, 0, 1}, 
				{1, 1, 0}};
		for (int i = 0; i < time-3; i++){
			nMatrix = transform(nMatrix);
		}
		return nMatrix;
	}

	@Override
	public String name() {
		return TModel.BARABASI.toString();
	}

}
